// 系统组织机构
function BasicOrganization_main() {
    return {
        dClick: function (cmp, r) {
            BasicOrganization_form().view({
                entityId: r.get('id')
            });
        },
        id: 'BasicOrganization_main',
        xtype: 'jgrid',
        clazz: BasicOrganization,
        order: ['state->desc', 'organSort->asc'],
        where: [['id', '!=', 'root'], ['organType', '=', 'area']],
        top: [{
            name: 'organName',
            op: 'like',
            text: '企业域名称',
            lw: 90,
            xtype: 'textfield'
        }, {
            name: 'organCode',
            op: 'like',
            text: '企业域编码',
            lw: 90,
            xtype: 'textfield'
        }, {
            xtype: 'textfield',
            lw: 90,
            name: 'organTel',
            op: 'like',
            text: '企业域电话'
        }, '|', {
            xtype: 'combo',
            name: 'state',
            text: '企业域状态',
            lw: 90,
            store: $.dic('state'),
            op: '='
        }, $.search, '->', {
            key: 'A',
            iconCls : 'fa-home',
            cls : 'violet',
            text: '创建企业域',
            handler: function () {
                BasicOrganization_form().save({
                    before : function(form) {
                        form.set('organCode', $.num('AREA'));
                    },
                    shir : 'basicOrganizationShir.createArea',
                    grid : ['BasicOrganization_main']
                });
            }
        }],
        cls : 'middle-grid',
        columns: [{
            text: 'LOGO',
            width: 120,
            xtype: "templatecolumn",
            tpl: "<img src=\"{organImg}\" style=\"max-height:60px;max-width:100px\"/>",
            "name": "organImg"
        }, {
            width: 150,
            text: "企业域名称",
            "name": "organName",
            renderer: function (v) {
                return "<span class='label label-primary'>" + v + "</span>";
            }
        }, {
            maxWidth: 50,
            text: "状态",
            renderer: $.yesNoRender(),
            "name": "state"
        }, {
            text: "企业域编码",
            width: 120,
            "name": "organCode"
        }, {
            text: '企业域联系方式',
            width: 120,
            "name": "organTel"
        }, {
            text: '企业域负责人',
            width: 140,
            "name": "organUserName"
        }, {
            text: '企业域负责人电话',
            width: 140,
            "name": "organUserPhone"
        }, {
            text: '创建人',
            width: 120,
            name: 'createUser'
        }, {
            text: "创建时间",
            width: 140,
            "name": "createDate"
        }, {
            width: 340,
            text: '企业域说明',
            name: 'memo',
            renderer: $.qtipRenderer()
        }, {
            xtype: "actioncolumn",
            text: '操作',
            flex: 1,
            items: [{
                getClass: function (v, meta, rec) {
                    return "x-fa " + (rec.get('state') == '1' ? ' fa-exclamation-triangle td-red' : 'fa-bolt td-green');
                },
                getTip: function (v, meta, rec) {
                    return rec.get('state') == '1' ? '停封企业域' : '启用企业域';
                },
                iconCls: 'fa-exclamation-triangle td-red x-fa',
                handler: function (grid, rowIndex, colIndex) {
                    var rec = grid.getStore().getAt(rowIndex);
                    var flag = (rec.get('state') == '1') ? '停封该企业域' : '启用该企业域';
                    $.confirm('确定' + flag, function () {
                        $.post('admin/basicOrganization/changeAreaState', {
                            id: rec.get('id'),
                            state: rec.get('state') == '1' ? 0 : 1
                        }, function (result) {
                            if (result) {
                                $.show(flag + "成功!");
                                $('BasicOrganization_main').search();
                            }
                        });
                    });
                }
            }, {
                iconCls: 'fa-pencil-square td-yellow x-fa',
                tooltip: '修改企业域',
                handler: function (grid, rowIndex, colIndex) {
                    var rec = grid.getStore().getAt(rowIndex);
                    $('BasicOrganization_main').select(rec);
                    BasicOrganization_form().edit({
                        title: '修改企业域',
                        grid: ['BasicOrganization_main']
                    });
                }
            }]
        }]
    }
}

function BasicOrganization_form() {
    return $({
        id : 'BasicOrganization_form',
        xtype : 'jform',
        clazz : BasicOrganization,
        hides : [{
            name : 'organParentId.id',
            value : 'root'
        }, {
            name : 'organType',
            value : 'area'
        }, {
            name : 'state',
            value : '1'
        }],
        validate : [['organCode = ?', 'organCode', '编码不能重复'], ['organUserPhone = ? ', 'organUserPhone', '该手机号已使用过']],
        fieldsSize : 0.5,
        defaults : {
            lw : 100
        },
        fields : [{
            req : true,
            text : '点击上传企业域图片',
            xtype : 'imgfield',
            name : 'organImg',
            listeners : {
                afterrender : function(cmp) {
                    // cmp.setValue('iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAIAAABMXPacAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA+NpVFh0WE1MOmNv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MYIAwgAHCAAYIAxggDGCAMIABwgAGCAMYIAxYtlwIMADPaI1VYPpyzAAAAABJRU5ErkJggg==');
                }
            }
        }, {
            text : '企业域编码',
            req : true,
            "name" : "organCode",
            minLength : 6,
            readOnly : true
        }, {
            text : '企业域排序',
            xtype : 'numberfield',
            "name" : "organSort",
            value : 1,
            maxLength : 5,
            minValue : 0
        }, {
            text : '企业域名称',
            req : true,
            "name" : "organName"
        }, {
            req : true,
            name : 'organUserName'
        }, {
            req : true,
            vtype : 'phone',
            name : 'organUserPhone'
        }, {
            text : '企业域电话',
            req : true,
            vtype : 'tel_phone',
            name : 'organTel'
        }, {
            text : '企业域简介',
            name : 'memo',
            xtype : 'textarea',
            size : 1
        }]
    })
}